/**
 * Quiz.js
 */
$(document).ready(function() {
	$('input').customInput();
	$('#submitBtn').click(function() {
		var allRadioBtns = $('#quizForm input:radio');
		var checkedRadioBtns = $('#quizForm input:radio:checked');
		if (checkedRadioBtns.length != (allRadioBtns.length/5)) {
			alert('请完成所有试题！');
			return false;
		}
		var answers = "";
		for ( var i = 0; i < checkedRadioBtns.length; i++) {
			answers += checkedRadioBtns[i].value + ":";
		}
		answers = answers.substring(0, answers.lastIndexOf(":"));
		var postData = "quizId=1&answers=" + answers;
		
		$.ajax({
			type : "POST",
			url : "/psytest-webapp/quizRecord",
			data : postData,
			success : function(msg) {
				alert('感谢您完成本次测试。\n接下来您可以查询自己的成绩或是退出本系统。');
				location.href="/psytest-webapp/user";
			}
		});
	});
});
